package com.kovell.profileo.flex.business
{
	import com.kovell.cairngormlite.CairngormliteCommand;
	import com.kovell.cairngormlite.CairngormliteEvent;
	import com.kovell.profileo.flex.model.ModelLocator;
	import com.kovell.profileo.flex.vo.User;
	
	import flash.events.Event;
	
	import mx.collections.ArrayList;
	import mx.controls.Alert;
	import mx.messaging.messages.ErrorMessage;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ArrayUtil;

	public class LoginCommand extends CairngormliteCommand
	{
		public function LoginCommand()
		{
//			this.isDelegate = false;
		}
		
		public override function onProcess(event:CairngormliteEvent):void{;
//			ModelLocator.getInstance().isLogin = true;
//			ModelLocator.getInstance().username = event.args.toString().split(",")[0];
		}
		
		public override function onFault(event:* = null):void{
			var errorMessage:ErrorMessage = (event as FaultEvent).message as ErrorMessage;
			Alert.show(errorMessage.faultString); //+ ", " + errorMessage.faultCode + ", " + errorMessage.faultDetail);
		}
		
		public override function onResult(event:* = null):void{
//			Alert.show(event)			
			var e:ResultEvent = event as ResultEvent;
			
			var user:User = (event as ResultEvent).result as User;
			
			ModelLocator.getInstance().isLogin =  true;			
			ModelLocator.getInstance().username = user.name;
		}
	}
}